package edu.ues21.tcs.ecommerce2011.mvc.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import edu.ues21.tcs.ecommerce2011.mvc.dao.ArticuloDAO;
import edu.ues21.tcs.ecommerce2011.mvc.dao.ArticuloPrecioDAO;
import edu.ues21.tcs.ecommerce2011.mvc.dao.ListaPrecioDAO;

/**
 * 
 * @author fmantaras
 */
public class EditArticuloPrecioController extends HttpServlet {

	ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
			"/BeanLocations.xml");

	ArticuloPrecioDAO apDao = (ArticuloPrecioDAO) appContext.getBean("articuloprecioDAO");
	ArticuloDAO aDao = (ArticuloDAO) appContext.getBean("articuloDAO");
	ListaPrecioDAO lDao = (ListaPrecioDAO) appContext.getBean("listaprecioDAO");

	
	private static final long serialVersionUID = 1L;

	protected void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

	}

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.getRequestDispatcher("view/AddListaPrecio.jsp").forward(
				request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		Integer idArticuloPrecio = Integer.parseInt(request.getParameter("idArticuloPrecio").trim());
		float precio = Float.parseFloat(request.getParameter("precio").trim());
		

		if (precio != 0 && idArticuloPrecio != null) {
			apDao.edit(precio, idArticuloPrecio);
		}

		response.sendRedirect("listarLP.do");

	}

	@Override
	public String getServletInfo() {
		return "Short description";
	}// </editor-fold>

}
